package com.sgb.kjwl.view.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.activity.PhotoViewActivity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.io.Serializable;
import java.util.List;

public class SimpleImageAdapter extends BaseRecycleAdapter<String> {

    private Intent intent;

    public SimpleImageAdapter(Context context, List<String> datas) {
        super(context, R.layout.item_image, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, String s) {
        ImageView iv = holder.itemView.findViewById(R.id.iv);
        Glide.with(context).load(s).into(iv);

        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                openPhotoView(holder.getPosition());
            }
        });
    }

    private void openPhotoView(int position) {
        if (intent == null) {
            intent = new Intent();
        }
        intent.setClass(context, PhotoViewActivity.class);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) datas);
        intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
        context.startActivity(intent);
    }
}
